package ACWing.SearchAndGraphTheory.DFS;
//93.递归实现组合型枚举

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @author :chenjie
 * @date :Created 2022/12/18 22:15
 */
public class RecursivelyImplementCompositionalEnumerations {
    static List<Integer> list=new ArrayList<>();
    static boolean[]arr=new boolean[25];
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int m=sc.nextInt();
        dfs(n,m);
    }
    public static void dfs(int n,int m,int x){//递归做法
        if(list.size()==m){
            for (int i = 0; i < m; i++) {
                System.out.print(list.get(i)+" ");
            }
            System.out.println();
            return;
        }
        for (int i = x+1; i <= n; i++) {
            if(!arr[i]){
                arr[i]=true;
                list.add(i);
                dfs(n,m,i);
                arr[i]=false;
                list.remove(list.size()-1);
            }
        }
    }
    public static void dfs(int n,int m){
        for (int i = 1; i <= n-2; i++) {
            for (int j = i+1; j <= n-1; j++) {

                for (int k = j+1; k <= n; k++) {

                    System.out.println(i+" "+j+" "+k);
                }
            }
        }

    }
}
